var dataurl;
var data;
var bardiv;
var tablediv;
var callback;

function gotopage(currentpage, pagesize, totalrows, totalpage) {
	if (isNaN(currentpage)) {
		alert("\u9875\u53f7\u5fc5\u987b\u662f\u6570\u5b57\uff01");
		return false;
	}

	if (currentpage < 1) {
		alert("输入的页号必须大于0!");
		return false;
	}

	if (currentpage > totalpage) {
		alert("输入的页号大于最大页数!");
		return false;
	}

	var url = dataurl + "?currentPage=" + currentpage;
	$.post(url, data, function(response) {
				document.getElementById(tablediv).innerHTML = response;
				if (callback != null) {
					callback();
				}
				var url1 = "../page/queryCommonPage2.action";
				$.post(url1, {
							"pageSize" : pagesize,
							"currentPage" : currentpage,
							"totalRows" : totalrows
						}, function(response) {
							document.getElementById(bardiv).innerHTML = response;
						});
			});
}

function querypage(obj) {
	if(!obj){
		return;
	}
	var url = obj.dataurl;
	dataurl = obj.dataurl;
	var currentpage = obj.currentpage;
	if (!currentpage) {
		currentpage = 1;
	}
	data = obj.data;
	bardiv = obj.bar;
	tablediv = obj.result;
	callback = obj.callback;
	$.post(obj.dataurl + "?currentPage=" + currentpage, obj.data, function(response) {
		var eleObj = document.getElementById(obj.result);
		if(eleObj){
			eleObj.innerHTML = response;
		}
		var tempurl = obj.pageurl;
		$.post(tempurl, obj.data, function(response) {
			var eleObj2 = document.getElementById(obj.bar);
			if(eleObj2){
				eleObj2.innerHTML = response;
			}
			if (obj.callback != null) {
				obj.callback();
			}
		});
	});
}
function querypage_total(obj) {
	var url = obj.dataurl;
	dataurl = obj.dataurl;
	data = obj.data;
	bardiv = obj.bar;
	tablediv = obj.result;
	callback = obj.callback;
	$.post(obj.dataurl, obj.data, function(response) {
				document.getElementById(obj.result).innerHTML = response;
				var tempurl = obj.pageurl + "?totalRows="
						+ document.getElementById("totalRows").value;
				$.post(tempurl, obj.data, function(response) {
							document.getElementById(obj.bar).innerHTML = response;
							if (obj.callback != null) {
								obj.callback();
							}
						});
			});
}

function doPageKeyDown(eventTag, currentpage, pagesize, totalrows, totalpage) {
	var event = eventTag || window.event;
	if (event.keyCode == 13) {
		gotopage(currentpage, pagesize, totalrows, totalpage);
	}
}

function querypageFirstStatic(obj, staticHtml) {
	var url = obj.dataurl;
	dataurl = obj.dataurl;
	data = obj.data;
	bardiv = obj.bar;
	tablediv = obj.result;
	callback = obj.callback;
	$.post(staticHtml, {}, function(response) {
				document.getElementById(obj.result).innerHTML = response;
				var tempurl = obj.pageurl;
				$.post(tempurl, obj.data, function(response) {
							document.getElementById(obj.bar).innerHTML = response;
							if (obj.callback != null) {
								obj.callback();
							}
						});
			});
}

function FormMenu(targ, selObj, restore) {
	// eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	eval("window.location='" + selObj.options[selObj.selectedIndex].value + "'");
	if (restore)
		selObj.selectedIndex = 0;
}
